#ifndef CBINARYCHUNK_H_
#define CBINARYCHUNK_H_

#include <fstream>
#include "cbinary.h"

/**
 * CBinaryChunk - abstract class representing chunk of binary file
 * @author Michal Rost
 * @date 20.10.2007
 */
class CBinaryChunk : public CObject {
public:
  void setId(unsigned short int id) {
    this->id = id;
  }
  unsigned short getId() const {
    return id;
  }
  unsigned int getLength() const {
    return length;
  }
  static string getClassName() {
    return "CBinaryChunk";
  }
protected:
  stringstream data;
  unsigned short int id;
  unsigned int length;
  virtual void init() = 0;
  void initData() {
    
    // Inicializace pomocneho streamu a prekopirovani do data (nelze pouzit
    // implicitni konstruktor pro data v deklaracni casti tridy, ani nelze
    // pouzit prirazeni, protoze proudy nemaji kopirovaci konstruktor)
    ios_base::openmode __m = ios_base::out | ios_base::in | ios_base::binary;
    stringstream tmp(__m);
    copyData(tmp);
  }
  void copyData(const stringstream &data) {
    this->data.copyfmt(data);
    this->data.clear(data.rdstate());
    this->data.str("");
    this->data << data.rdbuf();
  }
  void copyFrom(const CBinaryChunk &chunk) {
    id = chunk.id;
    length = chunk.length;
    copyData(chunk.data);
  }
};

#endif
